﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml.Serialization;
using System.Web.Script.Serialization;
using System.Data;
using RoadTeam.Pub;
using RoadTeam.BLL;
using RoadTeam.Standard;
using System.Text.RegularExpressions;

public partial class 对接测试页面_CsAcceptItem : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        CsAcceptItemBLL bll = new CsAcceptItemBLL();
        JavaScriptSerializer jscvt = new JavaScriptSerializer();
        CsAcceptItem model = jscvt.Deserialize<CsAcceptItem>(TextBox1.Text);
        if (model.Item.Length == 0) return;
        DataTable dt = bll.GetCsAcceptItemForEnptyTable();
        DataRow dr;
        foreach (AcceptItemTemp item in model.Item)
        {
            dr = dt.NewRow();
            dr["AcceptItemIdentifier"] = CreateIdentifier.GetIdentifier();
            dr["ListItemIdentifier"] = item.ListItemIdentifier;
            dr["InspectHouseIdentifier"] = item.InspectHouseIdentifier;
            dr["AcceptItemName"] = item.AcceptItemName;
            dr["AcceptItemContent"] = item.AcceptItemContent;
            dr["AcceptItemIsQualified"] = item.AcceptItemIsQualified;
            dr["AcceptItemSituation"] = item.AcceptItemSituation;
            dr["AcceptItemCharge"] = item.AcceptItemCharge;
            dr["AcceptItemChargeUnit"] = item.AcceptItemChargeUnit;
            dr["AcceptItemFinishDate"] = item.AcceptItemFinishDate;
            dr["AcceptItemRemark"] = item.AcceptItemRemark;
            item.AcceptItemIdentifier = dr["AcceptItemIdentifier"].ToString();
            dt.Rows.Add(dr);
        }
        bll.Insert(dt, TextBox1.Text);
        Response.Write(jscvt.Serialize(model));
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        List<AcceptItemTemp> list = new List<AcceptItemTemp>();
        AcceptItemTemp temp = new AcceptItemTemp();
        //temp.AcceptItemIdentifier = CreateIdentifier.GetIdentifier();
        temp.AcceptItemCharge = @"张三";
        temp.AcceptItemChargeUnit = @"中国第三研究院";
        temp.AcceptItemContent = @"验收房子屋顶是否漏水";
        temp.AcceptItemFinishDate = DateTime.Now.ToString();
        temp.ListItemIdentifier = CreateIdentifier.GetIdentifier();
        temp.InspectHouseIdentifier = CreateIdentifier.GetIdentifier();
        temp.AcceptItemIsQualified = true;
        temp.AcceptItemName = @"屋顶漏水";
        temp.AcceptItemRemark = @"这里是备注什么的";
        temp.AcceptItemSituation = @"情况一切良好";
        list.Add(temp);

        temp = new AcceptItemTemp();
        //temp.AcceptItemIdentifier = CreateIdentifier.GetIdentifier();
        temp.AcceptItemCharge = @"李四";
        temp.AcceptItemChargeUnit = @"中国第四研究院";
        temp.AcceptItemContent = @"验收房子墙壁油漆";
        temp.AcceptItemFinishDate = DateTime.Now.ToString();
        temp.ListItemIdentifier = CreateIdentifier.GetIdentifier();
        temp.InspectHouseIdentifier = CreateIdentifier.GetIdentifier();
        temp.AcceptItemIsQualified = true;
        temp.AcceptItemName = @"墙壁油漆";
        temp.AcceptItemRemark = @"这里是备注什么的";
        temp.AcceptItemSituation = @"情况一切良好";
        list.Add(temp);
        temp = new AcceptItemTemp();
        //temp.AcceptItemIdentifier = CreateIdentifier.GetIdentifier();
        temp.AcceptItemCharge = @"王五";
        temp.AcceptItemChargeUnit = @"中国第五研究院";
        temp.AcceptItemContent = @"窗户是否安装好";
        temp.AcceptItemFinishDate = DateTime.Now.ToString();
        temp.ListItemIdentifier = CreateIdentifier.GetIdentifier();
        temp.InspectHouseIdentifier = CreateIdentifier.GetIdentifier();
        temp.AcceptItemIsQualified = false;
        temp.AcceptItemName = @"窗户安装";
        temp.AcceptItemRemark = @"这里是备注什么的";
        temp.AcceptItemSituation = @"情况一切良好";
        list.Add(temp);

        CsAcceptItem li = new CsAcceptItem();
        li.Item = list.ToArray();

        JavaScriptSerializer jscvt = new JavaScriptSerializer();
        string str = jscvt.Serialize(li);


        str = Regex.Replace(str, @"\\/Date\((\d+)\)\\/", match =>
        {
            DateTime dt = new DateTime(1970, 1, 1);
            dt = dt.AddMilliseconds(long.Parse(match.Groups[1].Value));
            dt = dt.ToLocalTime();
            return dt.ToString("yyyy-MM-dd HH:mm:ss");
        });
        TextBox1.Text = str;


    }
}




//public class AcceptItemTemp
//{
//    [XmlElement(ElementName = "AcceptItemIdentifier", Type = typeof(string))]
//    public string AcceptItemIdentifier;
//    [XmlElement(ElementName = "ListItemIdentifier", Type = typeof(string))]
//    public string ListItemIdentifier;
//    [XmlElement(ElementName = "InspectHouseIdentifier", Type = typeof(string))]
//    public string InspectHouseIdentifier;
//    [XmlElement(ElementName = "AcceptItemName", Type = typeof(string))]
//    public string AcceptItemName;
//    [XmlElement(ElementName = "AcceptItemContent", Type = typeof(string))]
//    public string AcceptItemContent;
//    [XmlElement(ElementName = "AcceptItemIsQualified", Type = typeof(bool))]
//    public bool AcceptItemIsQualified;
//    [XmlElement(ElementName = "AcceptItemSituation", Type = typeof(string))]
//    public string AcceptItemSituation;
//    [XmlElement(ElementName = "AcceptItemCharge", Type = typeof(string))]
//    public string AcceptItemCharge;
//    [XmlElement(ElementName = "AcceptItemChargeUnit", Type = typeof(string))]
//    public string AcceptItemChargeUnit;
//    [XmlElement(ElementName = "AcceptItemFinishDate", Type = typeof(string))]
//    public string AcceptItemFinishDate;
//    [XmlElement(ElementName = "AcceptItemRemark", Type = typeof(string))]
//    public string AcceptItemRemark;
//}

//public class CsAcceptItem
//{
//    [XmlElement(ElementName = "Item")]
//    public AcceptItemTemp[] Item;
//}


